<template>
  <div class="item-container">
    <van-row type="flex" justify="center">
      <van-col>
        <!-- <img :src="detail.img" alt="" /> -->
        <van-image height="100vw" fit="contain" :src="detail.img" />
        
      </van-col>
    </van-row>

    <!-- 循环图片 -->
    <van-row type="flex" justify="center">
      <van-col span="24">
        {{ detail.miaoshu }}
      </van-col>
    </van-row>
 <!-- 通知栏可关闭 -->
<!-- 文字较短时，通过设置 scrollable 属性开启滚动播放 -->
<van-notice-bar scrollable text="2021年10月以后，鸿蒙系统将面向4GB以上所有设备开源" />
    <div>
    <!-- 优惠券单元格 -->
<van-coupon-cell
  :coupons="coupons"
  :chosen-coupon="chosenCoupon"
  @click="showList = true"
/>
<!-- 优惠券列表 -->
<van-popup
  v-model="showList"
  round
  position="bottom"
  style="height: 90%; padding-top: 4px;"
>
  <van-coupon-list
    :coupons="coupons"
    :chosen-coupon="chosenCoupon"
    :disabled-coupons="disabledCoupons"
    @change="onChange"
    @exchange="onExchange"
  />
</van-popup>
</div>


  


    <!-- 商品规格 -->
    <!-- <van-sku
  v-model="show"
  :sku="sku"
  :goods="goods"
  :goods-id="goodsId"
  :quota="quota"
  :quota-used="quotaUsed"
  :hide-stock="sku.hide_stock"
  :message-config="messageConfig"
  @buy-clicked="onBuyClicked"
  @add-cart="onAddCartClicked"
/> -->

    <!-- 底部按钮栏 -->
    <van-goods-action>
      <van-goods-action-icon icon="cart-o" text="购物车" url="http://localhost:8080/Cart"/>
      <van-goods-action-button type="warning" text="加入购物车" />
      <van-goods-action-button type="danger" text="立即购买" />
    </van-goods-action>
  </div>
</template>
<script>
import { Toast } from "vant";
import { mapState } from "vuex";
import Vue from 'vue';
import { CouponCell, CouponList } from 'vant';
Vue.use(CouponCell);
Vue.use(CouponList);
import { Sku } from 'vant';
Vue.use(Sku);

const coupon = {
  available: 1,
  condition: '无使用门槛\n最多优惠12元',
  reason: '',
  value: 150,
  name: '优惠券名称',
  startAt: 1489104000,
  endAt: 1514592000,
  valueDesc: '1.5',
  unitDesc: '元',
};
export default {
  data() {
    return {
      // 当前加载的商品详情
      detail: {},
      // 当前选中优惠券的索引
      chosenCoupon: -1,
      // 可用优惠券列表
      coupons: [coupon],
      // 不可用优惠券列表
      disabledCoupons: [coupon],
      // 定义showList为false
      showList:false,
      // show: false,
      // // 商品 sku 数据
      // sku: {
        
      // },
      // // 商品信息
      // goods: {
        
      // },
      // // 留言相关配置
      // messageConfig: {
        
      // },
      
    };
  },
    computed: {
    ...mapState(["baozheng", "guahua", "kezi", "dengshen", "dibu"]),
  },
  mounted() {
    const self = this;
    console.log("mounted", this.$route);
    const itemId = this.$route.query.id;
    if (!itemId) {
      Toast.fail("缺少参数");
      setTimeout(() => {
        self.$router.go(-1);
      }, 100);
      return;
    }
    
    // patch: 调用 API: getDetail(itemId)
    const item = this.$store.state.guahua.find((e) => e.id == itemId);
    console.log("getDetail", item);

    this.detail = item;
    
  },
  methods:{
    onChange(index) {
      this.showList = false;
      this.chosenCoupon = index;
    },
    onExchange() {
      this.coupons.push(coupon);
    },
  }
};
</script>
<style scoped>
</style>